import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);

        int n = sc.nextInt();
        int x = sc.nextInt();
        int[] arr = new int[n];
        int[] sub = new int[n]; // x 与 arr 数组中的元素的差
        long sum = 0;
        for (int i = 0; i < n; i++) {
            arr[i] = sc.nextInt();
            sum += arr[i];
            sub[i] = x - arr[i];
        }

        if (x == 0) {
            System.out.println(sum);
            return;
        }

        long[] dp = new long[n + 1];
        long max = 0;
        for (int i = 1; i < n + 1; i++) {
            dp[i] = Math.max(dp[i - 1] + sub[i - 1], sub[i - 1]);
            max = Math.max(dp[i], max);
        }

        System.out.println(max + sum);

        sc.close();
    }
}
